﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SM2SetupJobs;
using SM2Utilities;
using SM2Profile;

namespace SM2ReportAnalysis
{
    public class ThemesManager
    {
        public static void CreateThemeGraph(string strSelectedProfile, string strThemeName, string strGraphType, string strGraphCategories, string strDateRange)
        {
            strThemeName = strThemeName + Utilities.StringUtil.getTime();
            //Step1. Load Profiles
            CommonLoader.load("home.aspx");

            //Step2. Select profile
            ProfileActions.loadProfile(strSelectedProfile);

            //Step3. Select Theme Clouds report
            CommonLoader.load("result_clusters.aspx");

            //Setp4. Configure Report Setting
            //Hit New
            ThemesActions.hitNewGraphButton();

            //Select Basic or Advance
            ThemesActions.SelectGraphType(strGraphType);

            //Hit Next
            ThemesActions.hitNextGraphTypePage();
            
            ////Input Name
            ThemesActions.inputGraphName(strThemeName);

            //Hit Next
            ThemesActions.hitNextGraphNamePage();

            //Select filter by categories
            //Select All

            //Filter by date
            //Choose no dates, get all

            //Hit Next
            ThemesActions.hitNextSelectCategoryPage();

            //Hit Finish 
            ThemesActions.hitFinish();

            //Step5. Check Running/Completed 
            CommonLoader.load("jobs.aspx");
            RunningCompleted.checkJobStatus(strThemeName);

            //Step6. Check Theme > Report item            
            CommonLoader.load("result_clusters.aspx");
            ThemesActions.loadGraph(strThemeName);

            //Step7. Capture & attach to email
            //Path
            string path = Utilities.GlobalFolder.REPOSITORY_LOG_CURRENTLOG + strThemeName + ".jpg";
            System.Drawing.Bitmap bitmap = Utilities.GlobalObject.MANAGER.ActiveBrowser.Capture();
            bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            System.Threading.Thread.Sleep(1000);

            //Attachement
            Utilities.GlobalObject.MAIL.setAttachment(path);
            Utilities.GlobalObject.LOGGER.log("Captured, saved screenshot to log, and attached file to mail");
        }
    }
}
